package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.wms.domain.WmsStock;
import com.ruoyi.wms.service.IWmsStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsInventorySheet;
import com.ruoyi.wms.service.IWmsInventorySheetService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 盘点管理Controller
 * 
 * @author ruoyi
 * @date 2022-03-24
 */
@RestController
@RequestMapping("/wms/inventorySheet")
public class WmsInventorySheetController extends BaseController
{
    @Autowired
    private IWmsInventorySheetService wmsInventorySheetService;


    @Autowired
    private IWmsStockService wmsStockService;
    /**
     * 查询盘点管理列表
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:list")
    @GetMapping("/listWmsInventory")
    public TableDataInfo listWmsInventory(WmsInventorySheet wmsInventorySheet)
    {
        startPage();
        List<WmsInventorySheet> list = wmsInventorySheetService.listWmsInventory(wmsInventorySheet);
        return getDataTable(list);
    }

    /**
     * 查询盘点管理列表
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsInventorySheet wmsInventorySheet)
    {
        startPage();
        List<WmsInventorySheet> list = wmsInventorySheetService.selectWmsInventorySheetList(wmsInventorySheet);
        return getDataTable(list);
    }


    /**
     * 导出盘点管理列表
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:export")
    @Log(title = "盘点管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInventorySheet wmsInventorySheet) throws IOException
    {
        List<WmsInventorySheet> list = wmsInventorySheetService.selectWmsInventorySheetList(wmsInventorySheet);
        ExcelUtil<WmsInventorySheet> util = new ExcelUtil<WmsInventorySheet>(WmsInventorySheet.class);
        util.exportExcel(response, list, "盘点管理数据");
    }

    /**
     * 获取盘点管理详细信息
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:query")
    @GetMapping(value = "/{inventorySheetUuid}")
    public AjaxResult getInfo(@PathVariable("inventorySheetUuid") String inventorySheetUuid)
    {
        return AjaxResult.success(wmsInventorySheetService.selectWmsInventorySheetByInventorySheetUuid(inventorySheetUuid));
    }
 /**
     * 获取盘点管理详细信息
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:query")
    @GetMapping(value = "/flag/{inventorySheetUuid}")
    public AjaxResult getInfoFlag(@PathVariable("inventorySheetUuid") String inventorySheetUuid)
    {
        return AjaxResult.success(wmsInventorySheetService.selectWmsInventorySheetByUuid(inventorySheetUuid));
    }


    /**
     * 获取盘点管理详细信息
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:query")
    @GetMapping(value = "/loss/{inventorySheetUuid}")
    public AjaxResult getInfoLoss(@PathVariable("inventorySheetUuid") String inventorySheetUuid)
    {
        return AjaxResult.success(wmsInventorySheetService.selectWmsInventorySheetLoss(inventorySheetUuid));
    }

    /**
     * 新增盘点管理
     */
    @Transactional
    @PreAuthorize(hasPermi = "wms:inventorySheet:add")
    @Log(title = "盘点管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsInventorySheet wmsInventorySheet)
    {
//        WmsStock wmsStock = new WmsStock();
//        wmsStock.setSysNormalDisable("盘点中");
//        wmsStockService.updateWmsStock(wmsStock);
        wmsInventorySheet.setCreateBy(SecurityUtils.getUsername());
        return toAjax(wmsInventorySheetService.insertWmsInventorySheet(wmsInventorySheet));
    }

    /**
     * 修改盘点管理
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:edit")
    @Log(title = "盘点管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsInventorySheet wmsInventorySheet)
    {
        return toAjax(wmsInventorySheetService.updateWmsInventorySheet(wmsInventorySheet));
    }

    /**
     * 删除盘点管理
     */
    @PreAuthorize(hasPermi = "wms:inventorySheet:remove")
    @Log(title = "盘点管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventorySheetUuids}")
    public AjaxResult remove(@PathVariable String[] inventorySheetUuids)
    {
        return toAjax(wmsInventorySheetService.deleteWmsInventorySheetByInventorySheetUuids(inventorySheetUuids));
    }
}
